import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

/**
 * 存储登录用户信息的状态
 */
export const useLoginUserStore = defineStore('loginUser', () => {
  const loginUser = ref<any>({
    userName: '未登录',
  })

  async function fetchLoginUser() {
    // todo 由于后端还没提供接口，暂时注释
    setTimeout(() => {
      loginUser.value = { id: '1', userName: 'admin' }
    }, 3000)
  }

  /**
   * 设置登录用户
   * @param user
   */
  function setLoginUser(user: any) {
    loginUser.value = user
  }
  return { loginUser, fetchLoginUser, setLoginUser }
})
